﻿<?php 
//Lay thong tin cua mot cau hoi
if ($v_qa_id > 0) {
	$v_qa_agency_id = 		$arr_single_onegate_qa['1'];
	$v_qa_cate_id =   		$arr_single_onegate_qa['2'];
	$v_answerer_id =         $arr_single_onegate_qa['3'];
	$v_approver_id =         $arr_single_onegate_qa['4'];
	$v_qa_title =   	     $arr_single_onegate_qa['5'];
	$v_qa_content =          onegate_str_replace_char($arr_single_onegate_qa['6']); 
	$v_questioner_address =  $arr_single_onegate_qa['7'];
	$v_questioner_tel =      $arr_single_onegate_qa['8'];
	$v_questioner_email =    $arr_single_onegate_qa['9'];
	$v_questioner_website =  $arr_single_onegate_qa['10'];
	$v_answer_qa_content =   onegate_str_replace_char($arr_single_onegate_qa['11']);
	$v_question_date =       _yyyymmdd_to_ddmmyyyy($arr_single_onegate_qa['12']);	
	$v_answer_date =         _yyyymmdd_to_ddmmyyyy($arr_single_onegate_qa['13']);
	$v_approve_date =    	 _yyyymmdd_to_ddmmyyyy($arr_single_onegate_qa['14']);
	$v_qa_status =           $arr_single_onegate_qa['15'];
	$v_questioner_name = 	 $arr_single_onegate_qa['18'];
	$v_answerer_name = 	 $arr_single_onegate_qa['19'];
	
}
if(isset($_REQUEST['hdn_qa_content'])){
	$v_qa_content = $_REQUEST['hdn_qa_content'];
}
if(is_null($v_answer_date)||($v_answer_date == "")){
	$v_answer_date =  date("d/m/Y");
}
if(is_null($v_approve_date)||($v_approve_date == "")){
	$v_approve_date =  date("d/m/Y");
}
if($v_qa_status == 2) {
	$v_approved = "checked";
	$v_unapproved = "";
}else{
	$v_approved = "";
	$v_unapproved = "checked";
	$v_qa_status =1;
}
$v_exception_qa_id  = 0;
if(isset($_REQUEST['hdn_exception_qa_id'])){
	$v_exception_qa_id = intval($_REQUEST['hdn_exception_qa_id']);
}
$v_direction  = 'TOP';
if(isset($_REQUEST['hdn_direction'])){
	$v_direction = $_REQUEST['hdn_direction'];
}
$v_top_id  =   0;
if(isset($_REQUEST['hdn_top_id'])){
	$v_top_id = intval($_REQUEST['hdn_top_id']);
} 
$v_bottom_id = 0;
if(isset($_REQUEST['hdn_bottom_id'])){
	$v_bottom_id = intval($_REQUEST['hdn_bottom_id']);
}
// bieen dung de an nut cap nhat khi cau hoi da duoc duyet(xuat ban)
$str_disabled = "";
if($v_qa_id>0 && $v_qa_status==2){
	$str_disabled = "disabled";
}
$v_cate_id =0;
if(isset($_REQUEST['hdn_cate_id'])){
	$v_cate_id = intval($_REQUEST['hdn_cate_id']);
} 
$v_agency_id = 0;
if(isset($_REQUEST['hdn_agency_id'])){
	$v_agency_id = intval($_REQUEST['hdn_agency_id']);
}
$v_agency = "";
if(isset($_REQUEST['hdn_agency'])){
	$v_agency = $_REQUEST['hdn_agency'];
}
$v_filter = "";
if(isset($_REQUEST['hdn_filter'])){
	$v_filter = _replace_bad_char($_REQUEST['hdn_filter']);
}
//Luu ten cua linh vuc
$v_cate = "";
if(isset($_REQUEST['hdn_cate'])){
	$v_cate = $_REQUEST['hdn_cate'];
} 
$v_status = 0;
if(isset($_REQUEST['hdn_status'])){
	$v_status = $_REQUEST['hdn_status'];
}
if($v_approver_id == ""){
	$v_approver_id = $_SESSION['staff_id'];
}
// Goi thu tuc xu ly khi xoa cac file moi them (chua submit)
$v_goto_url_for_delete_file = "javascript:delete_row(document.all.tr_line_new,document.forms(0).chk_file_attach_new_id,document.forms(0).hdn_deleted_new_file_id_list);";
// Goi thu tuc de them moi dong
$v_goto_url_for_add_file = "javascript:add_row(document.all.tr_line_new," . CONST_QA_FILE_MAXLENGTH .");";
$v_url = "index.php";
?>
<!-- Bat cac phim: F12=true; Insert=false; Delete=false, ESC=true; Enter=true -->
<div id="hotkey" onKeyDown="javascript:process_hot_key(true,false,false,true,true);">
<!--bang chua tieu de cua form-->
<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr class="normal_title">
		<td><?php echo CONST_QA_QUESTION_FOR_ANSWER_TITLE; ?></td>
	</tr>
</table>
<!--bang chua cac text box de nhap du lieu-->
<table width="100%" class="form_table1" cellpadding="0" cellspacing="0" border="0">
  <col width="20%"><col width="30%"><col width="20%"><col width="30%">
    <!--forms chinh-->   
	  <form action="index.php" method="post" enctype="multipart/form-data" name="f_dsp_single_qa_question">
      <input type="hidden" name="fuseaction" value="DISPLAY_SINGLE_QA_QUESTION" >
      <input type="hidden" name="hdn_qa_id" value="<?php echo $v_qa_id; ?>">
      <input type="hidden" name="hdn_cate_id" value="<?php echo $v_cate_id; ?>">
	  <input type="hidden" name="hdn_qa_question_cate_id" value="<?php echo $v_qa_question_cate_id; ?>">
      <input type="hidden" name="hdn_approver_id" value="<?php $v_qa_approver_id; ?>">
	  <input type="hidden" name="hdn_filter" value="<?php echo $v_filter; ?>">
      <input type="hidden" name="hdn_accept" value="2">
	  <input type="hidden" name="hdn_qa_status" value="<?php echo $v_qa_status;?>">
	  <input type="hidden" name="hdn_status" value="<?php echo $v_status;?>">
      <input type="hidden" name="hdnContent" value='<? echo trim($v_qa_answer_content);?>'>
	  <input type="hidden" name="hdn_file_name" value="<?php echo $v_filename;?>">
	  <input type="hidden" name="hdn_cate" value="<?php echo $v_cate; ?>">
	  <input type="hidden" name="hdn_qa_content" value="<?php echo $v_qa_content; ?>">
	  <input type="hidden" name="hdn_answer_qa_content" value="<?php echo $v_answer_qa_content; ?>">
      <!---Luu ID cua cac file da co nhung da bi xoa-->
      <input type="hidden" name="hdn_deleted_exist_file_id_list" value="">
      <!---Luu ID cua cac file moi them nhung da bi xoa-->
      <input type="hidden" name="hdn_deleted_new_file_id_list" value="">
	  <input type="hidden" name="hdn_top_id" value="<?php echo $v_top_id; ?>">
	  <input type="hidden" name="hdn_bottom_id" value="<?php echo $v_bottom_id ?>">
	  <input type="hidden" name="hdn_direction" value="<?php echo $v_direction; ?>">
	  <input type="hidden" name="hdn_exception_qa_id" value="<?php echo $v_exception_qa_id; ?>">
	  <input type="hidden" name="hdn_agency" value="<?php echo $v_agency;?>">
	  <input type="hidden" name="hdn_agency_id" value="<?php echo $v_agency_id;?>">
  	  <input type="hidden" name="hdn_qa_cate_id" value="<?php echo $v_qa_cate_id;?>">
	  <input type="hidden" name="hdn_qa_agency_id" value="<?php echo $v_qa_agency_id;?>">
	  <input type="hidden" name="hdn_answerer_id" value="">
	  <input type="hidden" name="hdn_answerer_code" value=">">
	  <input type="hidden" name="hdn_handle_agency_id" value="0">
	  <input type="hidden" name="hdn_page" value="<?php echo $v_page;?>">
	  <script language="JavaScript"> 
		<!-- start Javascript-->
		_editor_url = "../isa-lib/js-editor/";                     
		var win_ie_ver = parseFloat(navigator.appVersion.split("MSIE")[1]);//Doan nay khoi tao de dung editor
		if (win_ie_ver >= 5.5) {
		   document.write('<scr' + 'ipt src="' +_editor_url+ 'editor.js" language="JavaScript"></scr' + 'ipt>');
		}else{ 
			document.write('<scr'+'ipt>function editor_generate() { return false; }</scr'+'ipt>'); 
		}		
	</script>
    <!--Bang chua cac Thong tin-->
 	<tr>
		<td class="normal_label"><?php echo CONST_CATE_LABEL;?></td>
		<td colspan="5">
			<select class="normal_selectbox" name="sel_cate" style="width:99%" message = "<?php echo CONST_CATE_MESSAGE; ?>" onChange="sel_onclick(this,document.forms(0).hdn_qa_cate_id);">>
            <option id="" value="">--<?php echo CONST_CATE_NAME_LABEL;?>--</option>
            <?php echo _generate_select_option($arr_all_cate_for_staff,'0','0','2', $v_qa_cate_id);?>
          </select>
		</td>
	</tr>
	<tr>
		<td class="normal_label" style="display:none">
			<?php echo CONST_AGENCY_UPDATE_LABEL;?>
		</td>
		<td colspan="3" style="display:none">
			<select class="normal_selectbox" name="sel_agency" style="width:99%" optional="<?php echo CONST_AGENCY_OPTIONAL;?>" message = "<?php echo CONST_AGENCY_MESSAGE; ?>" onChange="sel_onclick(this,document.forms(0).hdn_qa_agency_id);">>
            <option id="" value="">--<?php echo CONST_AGENCY_NAME_LABEL;?>--</option>
            <?php echo _generate_select_option($arr_all_agency_for_staff,'0','1','2', $_ISA_OWNER_CODE);?>
          </select>
		</td>  
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_QA_SENDER_NAME_LABEL;?><small class="normal_starmark">*</small></td>
		<td>
			<input type="text"  name="txt_qa_sender_name" class="normal_textbox" style="width:99%" value="<?php echo $v_questioner_name; ?>" optional="<? echo CONST_QA_SENDER_NAME_OPTIONAL; ?>" message="<?php echo CONST_QA_SENDER_NAME_MESSAGE;?>" onKeyDown="change_focus(document.forms(0),this)">
		</td>
		<td class="normal_label"><?php echo CONST_QA_SENDED_DATE_LABEL;?><small class="normal_starmark">*</small></td>
    	<td >
			<input type="text"  name="txt_qa_send_date" class="normal_date_textbox" readonly value="<?php echo $v_question_date; ?>" optional="<? echo CONST_QA_SENDED_DATE_OPTIONAL; ?>" onKeyDown="change_focus(document.forms(0),this)">
			<img src="<? echo $_ISA_IMAGE_URL_PATH;?>calendar.gif" border="0" onclick="DoCal('<?php echo $_ISA_LIB_URL_PATH; ?>isa-calendar/',document.forms(0).txt_qa_send_date)" style="cursor:hand;">
	    </td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_QA_SENDER_ADDRESS_LABEL;?></td>
		<td colspan="5">
			<input type="text" name="txt_qa_send_address" class="normal_textbox" style="width:99%"  value="<?php echo $v_questioner_address; ?>" optional="<? echo CONST_QA_SENDER_ADDRESS_OPTIONAL; ?>" onKeyDown="change_focus(document.forms(0),this)">
		</td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_QA_SENDER_TEL_LABEL;?></td>
		<td>
			<input type="text" name="txt_qa_send_tel" class="normal_textbox" style="width:99%" value="<?php echo $v_questioner_tel; ?>" optional="<? echo CONST_QA_SENDER_TEL_OPTIONAL; ?>" onKeyDown="change_focus(document.forms(0),this)">
		</td>
		<td class="normal_label"><?php echo CONST_QA_SENDER_EMAIL_LABEL;?></td>
		<td>
			<input type="text"  name="txt_qa_send_email" class="normal_textbox" style="width:99%" value="<?php echo $v_questioner_email; ?>" optional="<? echo CONST_QA_SENDER_EMAIL_OPTIONAL; ?>" onKeyDown="change_focus(document.forms(0),this)">
		</td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_QA_SENDER_WEBSITE_LABEL;?></td>
		<td colspan="5">
			<input type="text"  name="txt_qa_send_website" class="normal_textbox" style="width:99%" value="<?php echo $v_questioner_website; ?>" optional="<? echo CONST_QA_SENDER_WEBSITE_OPTIONAL; ?>" onKeyDown="change_focus(document.forms(0),this)">
		</td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_QA_QUESTION_TITLE_LABEL;?><small class="normal_starmark">*</small></td>
		<td colspan="5">
			<input name="txt_qa_question_title" type="text" class="normal_textbox" style="width:99%" value="<?php echo $v_qa_title; ?> "  optional="<?php echo CONST_QA_QUESTION_TITLE_OPTIONAL;?>" message="<?php echo CONST_QA_QUESTION_TITLE_MESSAGE;?>" onKeyDown="change_focus(document.forms(0),this)"  >
		</td>
	</tr>
	<tr>
		<td colspan="5" class="small_title"><? echo CONST_QA_QUESTION_CONTENT_LABEL;?><small class="normal_starmark">*</small></td>
	</tr>
	<tr>
		<td colspan="10">
			<textarea name="txt_qa_content" class="normal_textarea"  value="" rows="10" style="width:100%" optional="true" message ="<?php echo CONST_ARTICLE_NOTE_MESSAGE;?>"><?php echo $v_qa_content; ?></textarea>
			<script language="JavaScript1.2">editor_generate('txt_qa_content');//Goi ham tao editor trong file editor.js</script>
		</td>
	</tr><?php 	
			if(isset($arr_all_question_file)){
				$v_count = sizeof($arr_all_question_file);
			}else{
				$v_count = 0;
			}	
				if ($v_qa_id > 0 and $v_count>0) { 
			?>
	<tr>
		<td colspan="5" class="small_title"><? echo CONST_QUESTION_FILE_ATTACH_LABEL;?></td>
	</tr>
	<tr>
    	<td colspan="3">
		  <!--Bang chua cac file dinh kem-->
		  <table width="100%" cellpadding="0" cellspacing="0">
			<col width="15%"><col width="85%"> 
			<!--Vong lap hien thi cac file da dinh kem van ban--><?
			// Goi thu tuc xu ly khi xoa cac file da co
			for ($i=0; $i<$v_count; $i++) {
				$v_question_file_id = $arr_all_question_file[$i]['0'];
				$v_question_file_name = $arr_all_question_file[$i]['2']; 
				$v_file_url = trim(CONST_QA_URL_PATH_FROM_ROOT).$v_question_file_id.$v_question_file_name;
				$v_goto_url1 = "javascript:filename_onclick('T_ONEGATE_QA_FILE', 'PK_QA_FILE', 'C_FILE_NAME', 'C_FILE_CONTENT'," . strval($v_question_file_id) . ",'" . $v_file_url ."');" ;
				$target = "";?>
				<tr >
					<td>&nbsp;</td>
					<td><a href="<? echo $v_goto_url1; ?>" class="normal_link" <? echo $target;?>><img src="<? echo $_ISA_IMAGE_URL_PATH;?>file_attach.jpg" class="normal_image"><? echo $v_question_file_name;?></a> </td>
				</tr> <? 
			}?>
			</table>
		</td>
	</tr><?
	}?>
	<tr>
		<td height="1" colspan="12"><hr color="#66CCFF" size="1"></td>
	</tr>
	<tr>
    	<td colspan="5" class="small_title"><? echo CONST_QA_ANSWER_CONTENT_LABEL;?></td>
  </tr>
  <!-- Noi dung cau tra loi-->
	<tr>
		<td colspan="10">
			<textarea name="txt_answer_content" class="normal_textarea"  value="" rows="15" style="width:100%" optional="true" message ="<?php echo CONST_ARTICLE_NOTE_MESSAGE;?>"><?php echo $v_answer_qa_content; ?></textarea>
			<script language="JavaScript1.2">editor_generate('txt_answer_content');//Goi ham tao editor trong file editor.js</script>
		</td>
	</tr>
	<tr>
    	<td class="normal_label"><?php echo CONST_QA_ANSWERED_DATE_LABEL;?></td>
    <td>
		<input type="text"  name="txt_qa_answered_date" class="normal_date_textbox" isdate = "true" message = "<?php echo CONST_QA_DATE_MESSAGE; ?>"  value="<?php echo $v_answer_date; ?>" readonly optional="<? echo CONST_QA_ANSWERED_DATE_OPTIONAL; ?>" onKeyDown="change_focus(document.forms(0),this)">
		<img src="<? echo $_ISA_IMAGE_URL_PATH;?>calendar.gif" onclick="DoCal('<?php echo $_ISA_LIB_URL_PATH; ?>isa-calendar/',document.forms(0).txt_qa_answered_date)" style="cursor:hand;">
	</td>
		<td align="center" class="normal_label"><?php echo CONST_QA_APPROVED_DATE_LABEL;?>
		</td>
		<td colspan="3">
			<input type="text" name="txt_qa_approved_date" class="normal_date_textbox" isdate = "true" message = "<?php echo CONST_QA_DATE_MESSAGE; ?>" value="<?php echo $v_approve_date; ?>" onKeyDown="change_focus(document.forms(0),this)">
			<img src="<? echo $_ISA_IMAGE_URL_PATH;?>calendar.gif" border="0" onclick="DoCal('<?php echo $_ISA_LIB_URL_PATH; ?>isa-calendar/',document.forms(0).txt_qa_approved_date)" style="cursor:hand;">
		</td>
	</tr>
	<tr>
		<td class="normal_label"><?php echo CONST_QA_ANSWER_NAME_LABEL;?><small class="small_starmark">*</small></td>
		<td colspan="3">
			<input name="txt_answerer" type="text" class="normal_textbox" size="25" value="<?php echo $v_answerer_name; ?>"  message="<?php  echo CONST_RECEIVER_MESSAGE;?>" optional="<?php echo  CONST_RECORDTYPE_OPTIONAL;?>" onKeyDown=" change_focus(document.forms(0),this)">
			<img src="<? echo $_ISA_IMAGE_URL_PATH;?>find.gif" width="18" height="18" title="<?php echo  CONST_SHOW_CHOSICE_RECEIVER?>" class="normal_image" onClick="show_dialog_all_answerer_onclick('index.php','DISPLAY_ALL_STAFF_BY_UNIT',document.f_dsp_single_qa_question.txt_answerer,document.f_dsp_single_qa_question.hdn_answerer_code,document.f_dsp_single_qa_question.hdn_answerer_id,document.f_dsp_single_qa_question.hdn_handle_agency_id.value);document.f_dsp_single_qa_question.fuseaction.value='DISPLAY_SINGLE_QA_QUESTION';">
		</td>
  </tr>
  <tr>
    <td colspan="5" class="small_title"><? echo CONST_ANSWER_FILE_ATTACH_LABEL;?></td>
  </tr>
  <tr>
    <td colspan="10">
      <!--Bang chua cac file dinh kem-->
      <table width="100%" cellpadding="0" cellspacing="0" class="border_table1" border="0" >
        <col width="5%"><col width="5%"><col width="90%">
        <!--Vong lap hien thi cac file da dinh kem van ban--><?
		if(isset($arr_all_answer_file)){
			$v_answer_count = sizeof($arr_all_answer_file);
		}else{
			$v_answer_count = 0;
		}	
		if ($v_qa_id > 0 and $v_answer_count>0) {
			// Goi thu tuc xu ly khi xoa cac file da co
			$v_goto_url_for_delete_file = $v_goto_url_for_delete_file . "delete_row(document.all.tr_line_exist,document.forms(0).chk_file_attach_exist_id,document.forms(0).hdn_deleted_exist_file_id_list);";
			for ($i=0; $i<$v_answer_count; $i++) {
				$v_answer_file_id = $arr_all_answer_file[$i]['0'];
				$v_answer_file_name = $arr_all_answer_file[$i]['2']; 
				if(_is_sqlserver()){
					$v_file_url = trim(CONST_QA_URL_PATH_FROM_ROOT).$v_answer_file_id.$v_answer_file_name;
					$v_goto_url = "javascript:filename_onclick('T_ONEGATE_QA_FILE', 'PK_QA_FILE', 'C_FILE_NAME', 'C_FILE_CONTENT'," . strval($v_answer_file_id) . ",'" . $v_file_url ."');" ;
					$target = "";
				}?>
				<tr id="tr_line_exist">
					<td>&nbsp;</td>
					<td>
						<input type="checkbox" name="chk_file_attach_exist_id" value="<? echo $v_answer_file_id; ?>">&nbsp;
					</td>
					<td ><a href="<? echo $v_goto_url; ?>" class="normal_link"><img src="<? echo $_ISA_IMAGE_URL_PATH;?>file_attach.jpg" class="normal_image"><? echo $v_answer_file_name;?></a> </td>
				</tr><? 
			}
		}?>
        <!--Vong lap hien thi cac file dinh kem se them vao van ban-->
        <?
		for($i=0; $i<CONST_QA_FILE_MAXLENGTH; $i++){
			if ($i<=1 And $v_is_granted_qa_question_update) {
				$v_str_show="block";
			}else{
				$v_str_show="none";
			}?>
			<tr id="tr_line_new" style="display:<? echo $v_str_show;?>;">
				<td>&nbsp;</td>
				<td>
					<input type="checkbox" name="chk_file_attach_new_id" value="<? echo $i; ?>">
				</td>
				<td>
					<input type="file" name="file_attach<? echo $i;?>" style="width:98%" class="small_textbox" optional="<? echo CONST_QA_ATTACH_FILE_OPTIONAL;?>">
				</td>
			</tr><?
		}?>
        <!--Cac Button Them va Xoa file dinh kem van ban--><?
		if ($v_is_granted_qa_question_update) {
			$v_str_show="block";
		}else{
			$v_str_show="none";
		}?>
		<tr align="center" style="display:<? echo $v_str_show;?>;">
			<td colspan="5">
				<a href="<? echo $v_goto_url_for_add_file;?>" class="small_link" ><? echo _CONST_ADD_BUTTON;?></a> &nbsp; 
				<a href="<? echo $v_goto_url_for_delete_file;?>" class="small_link"><? echo _CONST_DELETE_BUTTON;?></a> </td>
		</tr>
    </table></td>
  </tr><?
	$v_granted_approver =  intval($arr_check_permission_approver['0']);
	if($v_granted_approver){?>
  <tr>
	<td colspan="10" class="normal_label">
		<input type="radio" class="normal_radiobutton" name="rad_accept" value="1" onClick="javascript:rad_accept_onclick();" <? echo $v_approved; ?>><?php echo CONST_QA_APPROVE_LABEL;?>&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="radio" class="normal_radiobutton" name="rad_accept" value="0" onClick="javascript:rad_accept_onclick();" <? echo $v_unapproved; ?>><?php echo CONST_QA_DENY_LABEL;?>
	</td>
  </tr><?
  }?>
</table>
<!--bang chua cac button-->
<table width="100%">
	<tr>
		<td align="center" width="100%" height="40" valign="bottom"><?php
		$v_granted_answer =  intval($arr_check_permission_answer['0']);
			if ($v_is_granted_qa_question_update && $v_granted_answer) { ?>
				<input type="button" name="btn_save"  class="normal_button" value="<?php echo _CONST_SAVE_BUTTON;?>" onClick="btn_save_onclick('UPDATE_QA_QUESTION');" onKeyDown="change_focus(document.forms(0),this)">&nbsp;&nbsp;&nbsp;&nbsp;<?php
			} ?>
			<input type="button" name="btn_back" class="normal_button" value="<?php echo _CONST_BACK_BUTTON;?>" onClick="btn_back_onclick('<?php echo $_GO_BACK?>');" onKeyDown="change_focus(document.forms(0),this)">
		</td>
	</tr>
</table>					
</form>
</div>
<script language="JavaScript">
	reshow_row(document.all.tr_line_exist,document.forms(0).chk_file_attach_exist_id,document.forms(0).hdn_deleted_exist_file_id_list);
	reshow_row(document.all.tr_line_new,document.forms(0).chk_file_attach_new_id,document.forms(0).hdn_deleted_new_file_id_list);
</script>
